package com.ailk.aee.pcc.action;

import com.ailk.aee.pcc.server.UserPloyStateServer;
import com.asiainfo.appserver.Action;
import com.asiainfo.appserver.Request;
import com.asiainfo.appserver.Response;
import com.asiainfo.appserver.annotations.Function;
import com.asiainfo.appserver.annotations.Parameter;
import com.asiainfo.appserver.annotations.Type;
import com.mongodb.BasicDBObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author pengzhang
 */
@Function(
        description = "查询用户策略", parameters = {
        @Parameter(name = "userId", type = Type.String, description = "用户ID", required = true),
        @Parameter(name = "ployCode", type = Type.String, description = "策略编码", required = true)

})
@Component
public class QueryPloyUserState implements Action {

    @Autowired
    private UserPloyStateServer ployServer;

    @Override
    public Response execute(Request request) throws Exception {
        String userId = request.getString("userId");
        String ployCode = request.getString("ployCode");
        BasicDBObject basicDBObject = ployServer.queryPloyUserState(userId, ployCode);

        Response response = new Response();
        if (basicDBObject != null) {
            basicDBObject.remove("_id");
            response.putAll(basicDBObject);
        }
        return response;
    }
}
